package me.hunche.app.exception;

/**
 * 
 * @author Wang, HaiLong. on 2012-10-22 17:44
 *
 */
public class ServiceException extends RuntimeException {
	
	private static final long serialVersionUID = -5022782739874182270L;
	
	public ServiceException(final String msg) {
		super(msg);
	}
	
	public ServiceException(final String msg, final Throwable e) {
		super(msg, e);
	}
	
	private static String fmt(final Throwable e) {
		return e.getClass().getSimpleName() + ": " + e.getMessage();
	}
	
	
	/*
	 * @see java.lang.Throwable#toString()
	 */
	@Override
	public String toString() {
		StringBuffer result = new StringBuffer(fmt(this));

		Throwable prev = null;
		Throwable e = getCause();
		while (e != null && e != prev) {
			result.append(" /// CAUSED BY " + fmt(e));
			prev = e;
			e = e.getCause();
		}

		return result.toString();
	}

}
